<template>
	<div style="display: flex;justify-content: space-between;">
		<h3>教师-显示</h3>
		<h3>
			<router-link to="/adm/tea/show"><button>返回</button></router-link>
		</h3>
		<h3>
			<button @click="go2Add()">继续添加</button>
		</h3>
	</div>
	<hr>
	<div style="width: 80%; border: 1px solid blue;">
		教师编号:<input type="text" v-model="tea.uid">
		<hr>
		教师姓名:<input type="text" v-model="tea.uname">
		<hr>
		教师电话:<input type="text" v-model="tea.phone">
		<hr>
		<p v-if="addstu==0">密码:<input type="text" v-model="tea.pwd"></p>
		图片:<input type="file" ref = "img">
		<button @click="add()" v-if="addstu==0">添加</button>
		<button @click="update()" v-if="addstu>0">修改</button>
	</div>
</template>

<script>
	export default{
		data() {
			return{
				tea:{uid:0},
				teaj:{uid:0},
				token:'',
				addstu:-1,  //-1 显示  0 添加  
			}
		},
		methods:{
			go2Add(){
				this.addstu = 0;
				let tea2 = JSON.stringify(this.teaj);
				this.tea = JSON.parse(tea2);
			},
			add(){
				let fd = new FormData();
				fd.append("uid",this.tea.uid);
				fd.append("uname",this.tea.uname);
				fd.append("phone",this.tea.phone);
				fd.append("pwd",this.tea.pwd);
				
				var  filex = this.$refs.img.files[0];  //获取文件上传第一个文件内容
				fd.append("mypic",filex);
				
				this.$postx("/api/adm/tea/add",fd)
				.then((resp)=>{
					console.log(resp.data);
				})
			},
			update(){
				let fd = new FormData();
				fd.append("uid",this.tea.uid);
				fd.append("uname",this.tea.uname);
				fd.append("phone",this.tea.phone);
				fd.append("pwd",this.tea.pwd);
				var  filex = this.$refs.img.files[0];  //获取文件上传第一个文件内容
				fd.append("mypic",filex);
				this.$postx("/api/adm/tea/update",fd)
				.then((resp)=>{
					console.log(resp.data);
					
				})
			}
			
		},
		mounted() {
			console.log("uid====");
			console.log(this.$route.query.uid);
			this.addstu = this.$route.query.uid;
			
			let path = "";
			path = "/"+this.$route.query.uid;
			if(this.$route.query.uid>0){
				this.$get("/api/adm/tea/findById",path)
				.then((resp)=>{
					console.log(resp.data.data)
					this.tea = resp.data.data
				})
			}
			
		}
	}
</script>

<style>
</style>
